package com.yqd.lesson.actor.four

import scala.concurrent.duration._
import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
import com.yqd.lesson.actor.four.Receiver.Greeting

object Receiver extends App {
  def props: Props = Props[Receiver]
  final case class Greeting(greeting: String)

  //启动当前actor
  val system = ActorSystem("akka");
  val receiver = system.actorOf(props,"receiver");
  println(receiver.path)
}

class Receiver extends Actor with ActorLogging {

  context.setReceiveTimeout(2000.second);

  def receive = {
    case Greeting(greeting) =>
      log.info(s"${sender().path} say: $greeting")
  }
}


